package com.example.fillthemapwithtubes.view;

import java.util.List;
import java.util.Map;

import com.example.fillthemapwithtubes.R;
import com.example.fillthemapwithtubes.common.Constants;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class ImageAdapter extends BaseAdapter {

	private Context context;
	private List<Map<String, Integer>> dataList;

	public ImageAdapter(Context context, List<Map<String, Integer>> dataList) {
		this.context = context;
		this.dataList = dataList;
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		FitImageView iv = null;
		if (convertView != null) {
			iv = (FitImageView) convertView;
		} else {
			iv = new FitImageView(context);
		}
		iv.setPadding(1, 1, 1, 1);
		iv.setImageResource(dataList.get(position).get(Constants.KEY_IMAGE));
		iv.setBackgroundResource(R.color.gray);
		return iv;
	}
}
